<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username',32)->comment('用户名');
            $table->string('avatar')->nullable()->comment('用户头像');
            $table->tinyInteger('gender')->default(0)->comment('用户性别');
            $table->string('email',64)->comment('用户邮箱');
            $table->char('nation_code',3)->nullable()->comment('国家码');
            $table->char('mobile_phone',11)->comment('手机号');
            $table->string('password')->comment('密码');
            $table->tinyInteger('state')->default(0)->comment('用户状态');
            $table->unsignedInteger('last_login_ip')->default(0)->comment('最后一次登录ip');
            $table->timestamp('last_login_at')->nullable()->comment('最后一次登录时间');
            $table->timestamp('registered_at')->nullable()->comment('注册时间');
            $table->timestamps();

            $table->comment("用户表");
        });


        Schema::create('user_login_logs', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger("uid")->comment("用户id");
            $table->string("login_from")->nullable()->comment("登录来源");
            $table->tinyInteger("login_result")->default(0)->comment("登录结果");
            $table->string("login_message")->nullable()->comment("登录消息");
            $table->unsignedInteger("login_ip")->default(0)->comment("登录ip");
            $table->string("browser")->nullable()->comment("浏览器标识");
            $table->string("os")->nullable()->comment("系统标识");
            $table->timestamps();
            $table->comment("用户登录日志表");
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('user_login_logs');
    }
};
